package cl.uchile.sketchpad.persistance.dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import cl.uchile.sketchpad.persistance.model.Group;


@Repository
public class GroupDaoImpl implements GroupDao {
	
	@PersistenceContext
	private EntityManager em; 

	@Override
	@Transactional(readOnly = true)
	public List<Group> getAllBySubjectVersionId(Integer id) {
		TypedQuery<Group> q = em.createQuery("from Group g where g.subject_version_id= :id ", Group.class);
		return q.getResultList();
	}

	@Override
	public Group findById(Integer id) {
		return em.find(Group.class, id);
	}
	
	@Override
	public void persist(Group g) {
		em.persist(g);
	}

}
